
angular.module('mamApp').controller('userBackPasswordController', ['$scope', 'AuthManager', '$state','ImsAlert','ImsErr', function ($scope, AuthManager, $state,ImsAlert,ImsErr) {
    $scope.user.redirectUrl='http://192.168.2.207/MAM_AP_WEB_V1/public/#/user/backPassword?step=3';
    var mailCheck=$state.params.mailCheck;
    $scope.disabled=false;
    $scope.passwordDisabled=false;
    $scope.error=true;
    $scope.step=$state.params.step||1;
    $scope.mailbox = function () {
        $scope.disabled=true;
       AuthManager.backPassword({redirectUrl: $scope.user.redirectUrl,userName:$scope.user.userName}).then(function (result) {
           $scope.disabled=false;
            if(result.data.c=="s"){
                $state.go($state.current.name,{step:2})
            }else {
                $scope.emailError=result.data.i;
            }
        })
    }

  $scope.sign=function(){
      $scope.passwordDisabled=true;
      AuthManager.mailUpdate({mailCheck:mailCheck}).then(function(result){
          if(result.data.c=="s"){
              $scope.passwordDisabled=false;
              localStorage.setItem("userInfo",JSON.stringify(result.data.userCpVO));
              AuthManager.resetPassword({newpwd:$scope.user.newpwd}).then(function(result){
                  if(result.data.c=="s"){
                      $scope.step=4
                  }
              })
          }else {
              ImsErr.open({message:result.data.i}).then(function (a) {
              })
          }
      })
  }


}])

